package com.xiangyueEducation.uploaderCloud.config;

import com.xiangyueEducation.uploaderCloud.interceptor.MyHandShakeInterceptor;
import com.xiangyueEducation.uploaderCloud.websocket.U2UChat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Component
@EnableWebSocket
@DependsOn("u2UChat")
public class WebSocketConfig implements WebSocketConfigurer {
    @Autowired
    U2UChat u2UChat;

    @Autowired
    MyHandShakeInterceptor myHandShakeInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(u2UChat,"/ws/chat")
                .addInterceptors(myHandShakeInterceptor)
                .setAllowedOrigins("*");
    }
}
